﻿using System.ComponentModel.DataAnnotations;
using UserData.Utils;

namespace UserData.Data
{
    public class User
    {
        public int Id { get; set; }

        [StringLength(30)]
        public string Name { get; set; }

        [StringLength(30)]
        public string Email { get; set; }

        [StringLength(16)]
        public string Password { get; set; }

        [StringLength(11)]
        public string Tel { get; set; }
        public DateTime DateTime { get; set; }
        public string Salt { get; set; }
        public void SetPassword(string password)
        {
            Salt = Guid.NewGuid().ToString();
            Password = HashUtils.Md5(Name + Salt + password);
        }

        public bool ValidatePassword(string password)
        {
            var hash = HashUtils.Md5(Name + Salt + password);
            return Password.Equals(hash, StringComparison.Ordinal);
        }
    }
}
